<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
add_action('admin_menu','z2gpanel');

function z2gpanel()
{
    add_menu_page('Z2G Categories Links Config','Z2G Categories Links','activate_plugins','z2glingsites/z2goptionspanel.php','z2g_render_panel',null,85);
}

function z2g_render_panel()
{
    
    if(isset($_POST['save-z2g-opt-panel'])){
        if(!wp_verify_nonce($_POST['z2glink_pannel_noncename'], 'z2glink-pannel')){
            die('Access restricted...');
        }else{
            foreach($_POST['options'] as $index=>$value){
                update_option($index, $value);
            }
        }
    }
?>
<div class='wrap theme-options-page'>
   <div id='icon-options-general' class="icon32">
    <br  />
    </div> 
    <h2>Categories Links Config</h2>
    <form  action="" method="POST" >
        <div class="theme-options-group">
            <table cellspacing="0" class="widefat options-table">
                <thead>
                    <tr>
                        <th colspan="2">Categories Name</th>
                    </tr>
                </thead>
                <tbody>
                     <?php
                     $categories =  get_categories();
                     foreach($categories as $category)
                     {
                      ?>
                      <tr>
                         <th scope="row" ><label for="<?=$category->cat_ID;?>"><?=$category->cat_name; ?></label></th>
                         <td>
                             <input size="100" type="text" value="<?=get_option('category-'.$category->cat_ID)?>" name="options[category-<?=$category->cat_ID ;?>]" id="Catgorie-<?=$category->cat_ID ;?>" />
                         </td>
                     </tr>
                      <?php   
                     }
                     ?>
                </tbody> 
            </table>
        </div>
        <input type="hidden" name="z2glink_pannel_noncename" value="<?=wp_create_nonce('z2glink-pannel')?>">
        <p class="submit"><input class="button-primary autowidth" type="submit" value="Save options"  name="save-z2g-opt-panel" /></p>
    </form>
</div>
<?php
}